<template>
	<div id="app" :class="[browser.isMobile ? 'app-mobile' : 'app-pc']" :style="contentWidthStyle">
		<router-view />
	</div>
</template>
<script>
import { mapGetters } from "vuex";
import * as dd from "dingtalk-jsapi";
import { isDev } from "@/config/env";
export default {
	computed: {
		...mapGetters(["browser"])
	},
	watch: {
		$route(to) {
			const firstPath = to.path.split("/")[1];
			if (firstPath == "mobilehome") {
				this.contentWidthStyle = { minWidth: "auto" };
			} else {
				this.contentWidthStyle = {};
			}
		}
	},
	data() {
		return {
			styleZoom: 1,
			contentWidthStyle: {}
		};
	},

	created() {
	
		console.log(dd.env.platform); //notInDingTalk不在钉钉环境中
		if (dd.env.platform != "notInDingTalk" && isDev) {
			// eslint-disable-next-line
			// const vConsole = new VConsole();
		}
		// 在钉钉环境中时 dd.env.platform//notInDingTalk不在钉钉环境中
		if (dd.env.platform !== "notInDingTalk") {
			dd.ready(() => {
				dd.biz.navigation.setRight({
					show: false //控制按钮显示， true 显示， false 隐藏， 默认true
				});
				dd.biz.navigation.setMenu({
					backgroundColor: "#ADD8E6",
					textColor: "#ADD8E611",
					items: [{ id: "1", iconId: "", text: "刷新", url: "" }],
					onSuccess: function(res) {
						location.reload();
						// 调用成功时回调
						console.log(res);
					},
					onFail: function(err) {
						// 调用失败时回调
						console.log(err);
					}
				});
			});
		}

		this.init();
	},
	methods: {
		init() {
			window.addEventListener(
				"keydown",
				e => {
					// 开启electron的调试
					var e = window.event || arguments[0];
					if (e.ctrlKey && e.key == "i") {
						const self = this;
						self.$ipcCall("controller.example.openViewDevelop").then(r => {
							console.log(r);
						});
					}
					// 缩放页面
					if (e.ctrlKey && e.key == "+") {
						this.styleZoom = this.styleZoom + 0.1;
						document.body.style.zoom = this.styleZoom;
					}
					if (e.ctrlKey && e.key == "-") {
						this.styleZoom = this.styleZoom - 0.1;
						document.body.style.zoom = this.styleZoom;
					}
					// if (e.ctrlKey && e.key == "b") {
					// 	// this.styleZoom = this.styleZoom - 0.1
					// 	// document.body.style.zoom = this.styleZoom
					// 	// document.body.createTextRange()
					// 	window.find('', false, false, true, false, true, true)
					// }
				},
				false
			);
		}
	}
};
</script>
<style lang="scss" src="./assets/css/index.scss"></style>
